import 'dart:convert';

import 'package:oi_ai_tool/model/chat_message.dart';

class Archive {
  List<ChatMessage> chatList;
  int? archiveTime;
  Archive({required this.chatList, this.archiveTime});

  Archive.formJson(Map<String, dynamic> data)
      : chatList = ChatMessage.formListJson(json.decode(data["chatList"])),
        archiveTime = json.decode(data["archiveTime"]);
  toJson() {
    return {
      "chatList": jsonEncode(chatList),
      "archiveTime": jsonEncode(archiveTime)
    };
  }

  static fromListJson(List<dynamic> jsonList) {
    List<Archive> msgList = [];
    if (jsonList.isNotEmpty) {
      for (var element in jsonList) {
        msgList.add(Archive.formJson(element));
      }
    }
    return msgList;
  }

  @override
  String toString() {
    return toJson().toString();
  }
}
